package pages;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import templates.Template;

/**
 * Servlet implementation class ErrorLogin
 */
public class ErrorLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ErrorLogin() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			Template template = new Template("errorlogin");
			response.getOutputStream().print(
					template.createPage("Authentication Error!", LMUtils
							.getUserLogin(request)));
		} catch (Exception e) {
			try {
				String userLogin = LMUtils.getUserLogin(request);
				response.getWriter().print(
						ErrorPage.generateErrorPage(e.getMessage(), userLogin));
			} catch (InternalErrorException e1) {
				response.getWriter().print(e1.getMessage());
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			Template template = new Template("errorlogin");
			response.getOutputStream().print(
					template.createPage("Authentication Error!", LMUtils
							.getUserLogin(request)));
		} catch (Exception e) {
			try {
				String userLogin = LMUtils.getUserLogin(request);
				response.getWriter().print(
						ErrorPage.generateErrorPage(e.getMessage(), userLogin));
			} catch (InternalErrorException e1) {
				response.getWriter().print(e1.getMessage());
			}
		}
	}

}
